using System;
using System.ComponentModel;

namespace Microsoft.Practices.Repository
{
    /// <summary>
    /// Utility class to cast DBNull.Value to the desired value, typically
    /// an empty string or a null value.
    /// </summary>
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Use Microsoft.Practices.Repository.CastDBValue", false)]
    public static class CastDBNull
    {
        /// <summary>
        /// Method return the value of the object casted to the type
        /// T if the value read is not DBNull.Value, else returns the default
        /// value specified in the input parameter.
        /// </summary>
        /// <typeparam name="T">The type to cast the database value to.</typeparam>
        /// <param name="value">The database value being read.</param>
        /// <param name="defaultValue">The value to assign when the value being read from the database is DBNull.Value.</param>
        /// <returns>The type specified.</returns>
        public static T To<T>(object value, T defaultValue)
        {
            return (value != DBNull.Value) ? (T)value : defaultValue;
        }
    }
}
